<template>
  <el-card class="box-card">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="/">数据统计</a></el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>

    <div class="Echarts">
      <div id="main" style="width: 600px;height:400px;" ref="main"></div>
    </div>
  </el-card>
</template>

<script>
import { getReports } from "../../api/index";
export default {
  name: "Echarts",
  data() {
    return {
      reportsData: "",
      options: {
        title: {
          text: "用户来源"
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#E9EEF3"
            }
          }
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true
        },
        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: "value"
          }
        ]
      }
    };
  },
  methods: {
    myEcharts() {
      // 基于准备好的dom，初始化echarts实例
      //   var myChart = this.$echarts.init(document.getElementById('main'));
      var myChart = this.$echarts.init(this.$refs.main);
      // 指定图表的配置项和数据
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(this.options);
    },
    async initGetReports() {
      let { data } = await getReports();
      this.reportsData = data;
      data.series.map(item => {
        item.type = "bar";
      });
      this.options = {
        ...this.options,
        ...this.reportsData
      };
    }
  },
  async mounted() {
    await this.initGetReports();
    await this.myEcharts();
  }
};
</script>
<style></style>
